/*
 * @Author: liuxiao
 * @Date: 2023-11-27 00:30:40
 * @Last Modified by: liuxiao
 * @Last Modified time: 2023-11-27 00:32:06
 * @ps:app层，导入koa，导入路由，统一错误处理
 */

const Koa = require('koa')
//导入koa-body
const { koaBody } = require('koa-body')

//导入错误处理函数
const errHandler = require('./errHandler')

const app = new Koa()

//用户相关路由
//const userRouter = require('../router/user.route')
//课程相关路由
//const courseRoute  = require('../router/course.route')

const router = require('../router')



//导入koaBody
app.use(koaBody())
//使用所有的路由规则
app.use(router.routes()).use(router.allowedMethods())
//导入路由
// app.use(userRouter.routes())
// app.use(courseRoute.routes())

//统一的错误处理,接受到emit发出的参数，
app.on('error', errHandler)

module.exports = app
